package stdying.handyweibo.injection.restmodule;

import com.squareup.okhttp.OkHttpClient;

import dagger.Module;
import dagger.Provides;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import stdying.handyweibo.injection.PreActivity;
import stdying.handyweibo.rest.RestConfig;

/**
 * Description: Retrofit2Module
 * Author: liulili
 * Created: 2015-11-24
 */
@Module(includes = OkHttpModule.class)
public class Retrofit2Module {
    /**
     * 提供retrofit
     * @param okHttpClient 网络连接对象
     * @return
     */
    @Provides
    @PreActivity
    Retrofit provideRetrofit(OkHttpClient okHttpClient){
        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(RestConfig.BASE_URL)
                        //使用okhttp
                .client(okHttpClient)
                        //添加gson转换
                .addConverterFactory(GsonConverterFactory.create())
                        //使用 RxJava 来代替 call, 你需要一个 Call Adapter Factory
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        return retrofit;
    }
}
